<?php
declare(strict_types=1);

/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/11
 * Time: 15:01
 */

namespace App\Model;
use Hyperf\Database\Model\Model;

class Admin extends Model
{
    protected ?string $table='admin';
    public bool $timestamps = true;

    protected array $hidden = [];

    protected array $fillable = ['name','password','phone','level','party_id'];



    /**
     * 根据uid获取管理员信息(brief)
     * @param int $admin_id
     * @return object
     */
    static public function getAdminInfoByUserIdBrief(int $admin_id): object
    {
        return Admin::where(['id'=>$admin_id])
            ->selectRaw('id,username,phone,level')
            ->first();
    }

    /**
     * 根据手机号获取管理员信息
     * @param string $phone
     * @return object
     */
    static public function getAdminInfoByPhone(string $phone): object
    {
        return Admin::where(['phone'=>$phone])
            ->selectRaw('id,username,phone,level')
            ->first();
    }


    /**
     * 根据admin_id获取管理员信息
     * @param int $admin_id
     * @return object
     */
    static public function getAdminInfoByUserId(int $admin_id): object
    {
        return Admin::find($admin_id);
    }

}